/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Partidas.java
 *
 * Created on 10/10/2009, 12:00:05 PM
 */

package Cliente;




import Conexion.Pais;
import Conexion.SerializedObject;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
//import risk.Tablero1;

/**
 *
 * @author Beto
 */
public class Partidas extends javax.swing.JFrame {
    private ImageIcon a14 = new ImageIcon(".//paises//wow-arquero.jpg");
    Cliente C;
    private String part;
    private int partidas;
   String partes;
    private boolean fin;
    private boolean est;
    ListaJugadores tab;
    SerializedObject so1;
    SerializedObject so2;
    String nombre;


    /** Creates new form Partidas
     * @throws IOException
     */
    public Partidas(Cliente Cs,SerializedObject so3,SerializedObject so4) throws IOException {

        initComponents();
        //this.tab=new ListaJugadores();
        //this.tab.setVisible(true);
        this.setSize(new Dimension(364, 400));
        this.getContentPane().setLayout(null);
        jLabel2.setBounds(new Rectangle(0, 0, 364, 400));
        jLabel2.setIcon(a14);

        //C=new Cliente();
        this.C=Cs;
        this.so1= so3;
        this.so2= so4;
        //C.crerConex("127.0.0.1",2000);
        this.est=true;
        int contador=1;
        System.out.println("hola");
       partidas=4;
        System.out.println(partidas);
        while (contador<=partidas){
             
             list1.add("partida"+contador);
             contador++;
        }


    }
  

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        list1 = new java.awt.List();
        button1 = new java.awt.Button();
        button2 = new java.awt.Button();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Partidas Disponibles");

        list1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                list1ActionPerformed(evt);
            }
        });

        button1.setEnabled(false);
        button1.setLabel("Conectarse");
        button1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                button1MouseClicked(evt);
            }
        });
        button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button1ActionPerformed(evt);
            }
        });

        button2.setLabel("cancelar");
        button2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button2ActionPerformed(evt);
            }
        });

        jLabel2.setText("jLabel2");

        jTextField1.setText("jTextField1");
        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField1KeyTyped(evt);
            }
        });

        jLabel3.setText("NombreJugador");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(list1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(45, 45, 45)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(button1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(button2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jTextField1)))))
                        .addGap(17, 17, 17))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(132, 132, 132)
                        .addComponent(jLabel2)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addGap(17, 17, 17)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(button2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(list1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(48, 48, 48))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_button1ActionPerformed

    private void button1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_button1MouseClicked
       
            // GENERA UNA ACCION SOBRE LA PARTIDA SELECCIONADA DE LA LISTA
            //SerializedObject so1= null;
            this.so1 = new SerializedObject();
            this.so2=null;
        String temp=null;
        String temp1=null;
        temp=Integer.toString(this.list1.getSelectedIndex()+1);
        partes=temp;
        this.so1.setTipoM("2");
        this.so1.setMensaje(temp);
        System.out.println(temp);
        
        
        temp=this.jTextField1.getText();
        this.so1.setName(temp);
        System.out.println(temp);
        System.out.println("esto es lo que hay guardado en name"+ this.so1.getName());
        this.nombre=this.so1.getName();
        C.enviar(this.so1);
        so2=C.recibir();
        System.out.println(so2.getMensaje());
         String[] RESP1=so2.getMensaje().split(" ");
     //     this.dispose();
          
        if(RESP1[0].equals("CONECTADO")){
            so1.setTipoM("0");
            C.enviar(so1);
            this.est=false;
            this.setVisible(false);
           
        }
         else{
             this.est=false;
           
                                    }
           
           this.setVisible(false);
        /*try {
          
            tab = new ListaJugadores(C);
        } catch (IOException ex) {
            Logger.getLogger(Partidas.class.getName()).log(Level.SEVERE, null, ex);
        }*/
         
        


     

    }//GEN-LAST:event_button1MouseClicked

    private void list1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_list1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_list1ActionPerformed

    private void button2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button2ActionPerformed
        // CIERRA LA VENTANA
        this.setVisible(false);


    }//GEN-LAST:event_button2ActionPerformed

    private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyTyped
       this.button1.setEnabled(true);
    }//GEN-LAST:event_jTextField1KeyTyped

    /**
     *
     */
   
    /**
    * @param args the command line arguments
    */
  

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Button button1;
    private java.awt.Button button2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField jTextField1;
    private java.awt.List list1;

    String getpartida() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
    // End of variables declaration//GEN-END:variables

   String getpartida1() {
        return this.partes;
    }
    String getName1(){
      return this.nombre;
  }

}
